<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="../../assets/js/vue.js"></script>
    <script type="text/javascript" src="../../assets/js/jquery-3.3.1.min.js"></script>
    <title>实例事件</title>
</head>
<body>
<div id="app">
    {{ score }}
</div>
<p><button onclick="reduce()">reduce</button></p>
<p><button onclick="reduceOnce()">reduceOnce</button></p>
<p><button onclick="off()">OFF</button></p>
<script type="text/javascript">
    var app = new Vue({
        el: "#app",
        data: {
            score: 0
        },
        methods: {
            add: function () {
                this.score++;
            }
        }
    })

    app.$on("reduce", function () {
        this.score--;
        console.log("执行了reduce()方法");
    })

    app.$once("reduceOnce", function () {
        this.score--;
        console.log("只能执行一次");
    })

    function reduce() {
        app.$emit("reduce");
    }

    function reduceOnce() {
        app.$emit("reduceOnce");
    }

    function off() {
        app.$off("reduce");
        console.log("关闭reduce()方法");
    }
</script>
</body>
</html>